package com.cn.hotel.servlet.back.order;

import com.cn.hotel.model.OrderModel;
import com.cn.hotel.service.IOrderService;
import com.cn.hotel.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/order/orderAdd")
public class OrderAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        String username = req.getParameter("username");
        String sex = req.getParameter("sex");
        String phone = req.getParameter("phone");
        String roomType = req.getParameter("roomType");
        String channel = req.getParameter("channel");
        String reservation = req.getParameter("reservationTime");
        String checkInTime = req.getParameter("checkInTime");
        String checkOutTime = req.getParameter("checkOutTime");

        OrderModel orderModel = new OrderModel();
        orderModel.setUsername(username);
        orderModel.setSex(sex);
        orderModel.setPhone(phone);
        orderModel.setRoomType(roomType);
        orderModel.setChannel(channel);
        orderModel.setReservationTime(reservation);
        orderModel.setCheckInTime(checkInTime);
        orderModel.setCheckOutTime(checkOutTime);
        IOrderService iOrderService = new OrderServiceImpl();
        int result = iOrderService.add(orderModel);
        resp.getWriter().println(result);
    }
}
